define(['jquery', 'bootstrap', 'userend', 'table', 'form'], function ($, undefined, Userend, Table, Form) {

    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: 'user/importquestion/index' + location.search,
                    add_url: 'user/importquestion/add',
                    //edit_url: 'user/importquestion/edit',
                    del_url: 'user/importquestion/del',
                    multi_url: 'importquestion/multi',
                    import_url: 'importquestion/import',
                    table: 'import_question',
                }
            });

            var table = $("#table");

            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                pk: 'id',
                sortName: 'id',
                columns: [
                    [
                        {checkbox: true},
                        {field: 'id', title: __('导入编号')},
                        {field: 'course_name', title: __('导入题库')},
                        {field: 'extend_name', title: __('导入分类')},
                        {field: 'name', title: __('试卷名称')},
                        {
                            field: 'status',
                            title: __('导入状态'),
                            formatter: Table.api.formatter.normal,
                            searchList: {1: __('等待导入'), 2: __('导入成功'),3: __('导入失败')}
                        },
                        {field: 'error', title: __('错误信息')},
                        {
                            field: 'create_time',
                            title: __('创建时间'),
                            addclass: 'datetimerange',
                            formatter: Table.api.formatter.datetime,
                        },
                        {
                            field: 'update_time',
                            title: __('更新时间'),
                            addclass: 'datetimerange',
                            formatter: Table.api.formatter.datetime,
                        },
                        {
                            field: 'operate',
                            title: __('Operate'),
                            table: table,
                            buttons: [
                                {
                                    name: 'detail',
                                    text: '重新导入',
                                    title: '重新导入',
                                    icon: 'fa fa-upload',
                                    hidden:function (row) {
                                        return row.status!=3;
                                    },
                                    classname: 'btn btn-xs btn-primary btn-dialog',
                                    url: 'user/importquestion/edit'
                                }
                            ],
                            events: Table.api.events.operate,
                            formatter: Table.api.formatter.operate
                        }
                    ]
                ]
            });

            // 为表格绑定事件
            Table.api.bindevent(table);
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});
